﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

namespace WebTest
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mm = new MailMessage();
                mm.From = new MailAddress(txtServerName.Text);
                mm.To.Add(new MailAddress(txtToEmail.Text));
                mm.Subject = txtTitle.Text;
                mm.Body = txtContent.Text;
                mm.IsBodyHtml = true;
                mm.BodyEncoding = System.Text.Encoding.UTF8;
                mm.Priority = MailPriority.Normal;

                SmtpClient sc = new SmtpClient();
                sc.Host = txtSMTP.Text;
                sc.UseDefaultCredentials = true;
                sc.Credentials = new System.Net.NetworkCredential(txtServerName.Text.Substring(0, txtServerName.Text.IndexOf('@')), txtServerPass.Text);
                sc.DeliveryMethod = SmtpDeliveryMethod.Network;
                sc.Send(mm);

                lbResult.Text = "success";
            }
            catch (Exception ex)
            {
                lbResult.Text = ex.Message + ex.StackTrace;
            }
        }
    }
}